<?php
class CalendarComponent extends Object{
	var $components = array( 'Auth','Session','RequestHandler');	

	
	public function homepage($params){
		$model =& $this->getModel('News');
	    if(!$model){
	      return false;
	    }
	    $product_schema = $model->schema();
	    $fields = array('NewUpload.name');
		    if(is_array($product_schema)){
	    	foreach ($product_schema as $column => $value) {
	    		array_push($fields,"News.{$column}");
	    	}
	    }else{
	    	$fields = array('News.id','News.name','News.views','News.small_content','NewUpload.name');
	    }
	    $joins = array( array('table' => 'new_uploads', 'alias' => 'NewUpload', 'type' => 'LEFT', 'conditions' => array( 'NewUpload.id = News.new_upload_id')));
	    
	    $items = $model->find('all',array('fields'=>$fields,'joins'=>$joins,'order'=>array('News.on_date'=>'DESC'),'limit'=>$params['limit']));
	    return $items;	    
	}
	
	public function events($params){
		$model =& $this->getModel('News');
	    if(!$model){
	      return false;
	    }
	    $product_schema = $model->schema();
	    $fields = array('NewUpload.name');
		    if(is_array($product_schema)){
	    	foreach ($product_schema as $column => $value) {
	    		array_push($fields,"News.{$column}");
	    	}
	    }else{
	    	$fields = array('News.id','News.name','News.views','News.small_content','NewUpload.name');
	    }
	    $joins = array( array('table' => 'new_uploads', 'alias' => 'NewUpload', 'type' => 'LEFT', 'conditions' => array( 'NewUpload.id = News.new_upload_id')));
	    
	    $items = $model->find('all',array('fields'=>$fields,'joins'=>$joins,'conditions'=>$params['conditions'],'order'=>array('News.on_date'=>'DESC'),'limit'=>$params['limit']));
	    return $items;	    
	}
	
	function &getModel($name = null) {
		$model = null;
		if (!$name) {
			$name = 'News';
		}    
		if($name){
			if (PHP5) {
				$model = ClassRegistry::init($name);
			} else {
				$model =& ClassRegistry::init($name);
			}

			if (empty($model)) {
//				$this->_error('FileUpload::getModel() - Model is not set or could not be found');
				return null;
			}
		}
		return $model;
	}
}